{% extends 'frame.html' %}
{% block title %}Automagic{% endblock %}
{% block slideshow %}
    {% if request.user.is_staff %}
        <div class="ak-zper-midbox ak-jsch-mid">
            <div class="ak-zper-inbox-title ak-jsch-title clearfix">
                <div class="ak-left ak-jsch-row3 ak-zper-fix-btnbox">
                    <span class="ak-zper-remindback"></span>
                    <span class="inbox-text">用户管理</span>
                </div>
                <div id="log_info" class="ac-addtips"></div>
            </div>

            <!--      ---------------------华丽的分割线 main------------------------ -->
            <div class="col-md-12">
                <div class="ac-margin-tb15">

                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <form class="form-inline" role="form" action="" method="GET">
                                <div class="input-group">
                                    <input type="input" class="form-control search-width" name="keyword"
                                           value="{{ request.GET.keyword }}" placeholder="用户名、邮箱、手机号搜索">
                                    <span class="input-group-btn">
                                      <button class="btn btn-primary" type="submit">Go!</button>
                                  </span>
                                </div>
                                <a href="" class="ak-right ac-btn-addcase orange" data-toggle="modal"
                                   data-target="#ProductAndUserModal">关联产品</a>
                                <a href="" class="ak-right ac-btn-adduser blue ac-amargin-r10" data-toggle="modal"
                                   data-target="#addUserModal">创建用户</a>
                            </form>
                            {#                            <div align="right" class="form-group">#}
                            {#                                <a href="/user/add/" class="ak-left ac-btn-adduser orange" >创建用户</a>#}
                            {##}
                            {#                            </div>#}
                            <!-- /input-group -->
                        </div>

                        <table id="mytable" class="table table-striped  table-hover table-condensed ac-aelement-table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>真实姓名</th>
                                <th>管理员</th>
                                <th>部门</th>
                                <th>状态</th>
                                <th>邮箱</th>
                                <th>手机</th>
{#                                <th>TestRail用户名</th>#}
                                <th>关联产品</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for user in userlist %}
                                <tr>
                                    <td>{{ user.pk }}</td>
                                    <td>{{ user.username }}</td>
                                    <td>{{ user.realname }}</td>
                                    <td>
                                        {% if user.is_staff == 1 %}
                                            <span ng-if="f.flag==true" class="label label-success ng-scope">YES</span>
                                        {% else %}
                                            <span ng-if="f.flag==false" class="label label-danger ng-scope">NO</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ user.dept }}</td>
                                    <td>
                                        {% if user.is_active == 1 %}
                                            <span ng-if="f.flag==true" class="label label-success ng-scope">可用</span>
                                        {% else %}
                                            <span ng-if="f.flag==false" class="label label-danger ng-scope">不可用</span>
                                        {% endif %}
                                    </td>
                                    <td>{{ user.email }}</td>
                                    <td>
                                        {% if user.mobile %}
                                            {{ user.mobile }}
                                        {% endif %}
                                    </td>
{#                                    <td title="{{ user.testrailpass }}">#}
{#                                        {% if user.testrailuser %}#}
{#                                            {{ user.testrailuser }}#}
{#                                        {% endif %}#}
{#                                    </td>#}
                                    <td class="ac-alist-width-overflow-public">
                                        {% for i in userandproduct %}
                                            {% if i.username == user %}
                                                {{ i.productname.name }};
                                            {% endif %}
                                        {% endfor %}
                                    </td>
                                    <td>
                                        <a href="" onclick="setuserValue({{ user.id }})" class="ke-ablock"
                                           data-toggle="modal" data-target="#editUserModal"><i
                                                class="glyphicon glyphicon-edit"></i></a>
                                        {#                                        <a href="{% url 'userdel' user.id %}" class="ke-ablock"#}
                                        {#                                           onclick="return confirm('您确定要删除吗？')"><i#}
                                        {#                                                class="glyphicon glyphicon-trash"></i></a>#}
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% if is_paginated %}
                        <div class="panel-default">
                            <ul class="pagination">
                                <li>
                                    <a href="javascript:window.location.href=window.location.search.match(/page=(\d+|\s*)/)===null? window.location.origin+(window.location.pathname +'?page=1'+(window.location.search?window.location.search.replace('?','&'):'')):window.location.search.replace(/page=(\d+|\s*)/, 'page=1')">«</a>
                                </li>
                                {% if page_obj.has_previous %}
                                    <!--<li><a href="{{ request.get_full_path }}&page={{ page_obj.previous_page_number }}">上一页</a></li>-->
                                    <li>
                                        <a href="javascript:window.location.href=window.location.search.match(/page=(\d+|\s*)/)===null? window.location.href +'?page={{ page_obj.previous_page_number }}': window.location.search.replace(/page=(\d+|\s*)/, 'page={{ page_obj.previous_page_number }}')">上一页</a>
                                    </li>
                                {% else %}
                                    <li class="previous disabled"><a>上一页</a></li>
                                {% endif %}
                                {% for i in page_obj.paginator.page_range %}
                                    <li {% if page_obj.number == i %}class="active"{% endif %}><a
                                            href="javascript:window.location.href=window.location.search.match(/page=(\d+|\s*)/)===null? window.location.origin+(window.location.pathname +'?page={{ i }}'+(window.location.search?window.location.search.replace('?','&'):'')):window.location.search.replace(/page=(\d+|\s*)/, 'page={{ i }}')">{{ i }}</a>
                                    </li>
                                {% endfor %}
                                {% if page_obj.has_next %}
                                    <li>
                                        <a href="javascript:window.location.href=window.location.search.match(/page=(\d+|\s*)/)===null? window.location.origin+(window.location.pathname +'?page={{ page_obj.next_page_number }}'+(window.location.search?window.location.search.replace('?','&'):'')):window.location.search.replace(/page=(\d+|\s*)/, 'page={{ page_obj.next_page_number }}')">下一页</a>
                                    </li>
                                {% else %}
                                    <li class="previous disabled"><a>下一页</a></li>
                                {% endif %}
                                <li>
                                    <a href="javascript:window.location.href=window.location.search.match(/page=(\d+|\s*)/)===null? window.location.origin+(window.location.pathname +'?page={{ page_obj.paginator.num_pages }}'+(window.location.search?window.location.search.replace('?','&'):'')):window.location.search.replace(/page=(\d+|\s*)/, 'page={{ page_obj.paginator.num_pages }}')">»</a>
                                </li>
                                <li><a>当前第{{ page_obj.number }}页/共{{ usersum }}个用户</a></li>
                                <li><input id="curpage" class="ac-acaseedit-input" type="number" style="width: 80px;">
                                </li>
                                <li>
                                    <button id="btn_skip" onclick="btn_skip_click()" type="button"
                                            class="btn btn-sm btn-primary">确定
                                    </button>
                                </li>
                            </ul>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
        <!--      ---------------------华丽的分割线 main end------------------------ -->
        <!--Add Modal -->

        <div class="modal fade ak-min-fullwidth-modal ak-znews-addsort-modal" id="addUserModal" tabindex="-1"
             role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header clearfix">
                        <button type="button" class="close close-back" data-dismiss="modal"><span
                                class="sr-only">Close</span></button>
                        <h4 class="modal-title text-center">创建用户</h4>
                    </div>
                    <div class="modal-body col01 ac-amargin-tb20">
                        <form id="user_add" method="post" action="{% url 'adduser' %}" class="form-horizontal">

                            <div class="form-group">
                                <label class="col-lg-3 control-label">用户名</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="username" placeholder="请填写登录用户名"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-lg-3 control-label">密码</label>
                                <div class="col-lg-5">
                                    <input type="password" class="form-control" name="password" placeholder="请填写登录密码"/>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">确认密码</label>
                                <div class="col-lg-5">
                                    <input type="password" class="form-control" name="confirmPassword"
                                           placeholder="请填写确认密码"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">邮箱地址</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="email" placeholder="请填写电子邮箱地址"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-lg-3 control-label">真实姓名</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="realname" placeholder="请填写用户真实姓名"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">手机号码</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="mobile"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">部门</label>
                                <div class="col-lg-5">
                                    <select name="dept" class="ak-left ac-aselect">
                                        <option value="研发">研 发</option>
                                        <option value="测试">测 试</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">激活状态</label>
                                <div class="col-lg-3">
                                    <div class="sky-form">
                                        <label class="toggle">
                                            <input id="id_is_active" type="checkbox" checked="checked" name="is_active">
                                            <i class="rounded-4x ak-aoffon-btn col01"></i>
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">管理员</label>
                                <div class="col-lg-3">
                                    <div class="sky-form">
                                        <label class="toggle">
                                            <input id="id_is_admin" type="checkbox" name="is_admin">
                                            <i class="rounded-4x ak-aoffon-btn col01"></i>
                                        </label>
                                    </div>
                                </div>
                            </div>

{#                            <div class="form-group">#}
{#                                <label class="col-lg-3 control-label">TestRail用户名</label>#}
{#                                <div class="col-lg-5">#}
{#                                    <input type="text" class="form-control" name="testrailuser"#}
{#                                           placeholder="请填写TestRail的登录用户名"/>#}
{#                                </div>#}
{#                            </div>#}
{#                            <div class="form-group">#}
{#                                <label class="col-lg-3 control-label">TestRail密码</label>#}
{#                                <div class="col-lg-5">#}
{#                                    <input type="text" class="form-control" name="testrailpass"#}
{#                                           placeholder="请填写TestRail的登录密码"/>#}
{#                                </div>#}
{#                            </div>#}
                            <div class="form-group modal-footer">
                                <div class="col-lg-9 col-lg-offset-3">
                                    <!--===footer button ===-->
                                    <div class="ak-footer-btn text-left">
                                        <input class="ak-zdl-createbtn" type="submit" value="提交">
                                        <input class="ak-zdl-createbtn cancel" type="reset" value="重置">
                                    </div>
                                    <!--===End footer button ===-->
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- Edit Modal -->
        <div class="modal fade ak-min-fullwidth-modal ak-znews-addsort-modal" id="editUserModal" tabindex="-1"
             role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header clearfix">
                        <button type="button" class="close close-back" data-dismiss="modal"><span
                                class="sr-only">Close</span></button>
                        <h4 class="modal-title text-center">编辑用户</h4>
                    </div>
                    <div class="modal-body col01 ac-amargin-tb20">
                        <form id="user_edit" method="post" action="{% url 'userupdate' %}" class="form-horizontal">

                            <div class="form-group">
                                <label class="col-lg-3 control-label">用户名</label>
                                <div class="col-lg-5">
                                    <input name="userid" hidden="true">
                                    <input type="text" class="form-control" name="username" readonly="true"
                                           placeholder="请填写登录用户名"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-lg-3 control-label">密码</label>
                                <div class="col-lg-5">
                                    <input type="password" class="form-control" name="password" placeholder="登录密码"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">确认密码</label>
                                <div class="col-lg-5">
                                    <input type="password" class="form-control" name="confirmPassword"
                                           placeholder="确认密码"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">邮箱地址</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="email" placeholder="请填写电子邮箱地址"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-lg-3 control-label">真实姓名</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="realname" placeholder="请填写用户真实姓名"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">手机号码</label>
                                <div class="col-lg-5">
                                    <input type="text" class="form-control" name="mobile"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">部门</label>
                                <div class="col-lg-5">
                                    <select name="dept" class="ak-left ac-aselect">
                                        <option value="研发">研 发</option>
                                        <option value="测试">测 试</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">激活状态</label>
                                <div class="col-lg-3">
                                    <div class="sky-form">
                                        <label class="toggle">
                                            <input id="edit_id_is_active" type="checkbox" checked="checked" name="is_active">
                                            <i class="rounded-4x ak-aoffon-btn col01"></i>
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">管理员</label>
                                <div class="col-lg-3">
                                    <div class="sky-form">
                                        <label class="toggle">
                                            <input id="edit_id_is_admin" type="checkbox" checked="checked" name="is_admin">
                                            <i class="rounded-4x ak-aoffon-btn col01"></i>
                                        </label>
                                    </div>
                                </div>
                            </div>

{#                            <div class="form-group">#}
{#                                <label class="col-lg-3 control-label">TestRail用户名</label>#}
{#                                <div class="col-lg-5">#}
{#                                    <input type="text" class="form-control" name="testrailuser"#}
{#                                           placeholder="请填写TestRail的登录用户名"/>#}
{#                                </div>#}
{#                            </div>#}
{#                            <div class="form-group">#}
{#                                <label class="col-lg-3 control-label">TestRail密码</label>#}
{#                                <div class="col-lg-5">#}
{#                                    <input type="text" class="form-control" name="testrailpass"#}
{#                                           placeholder="请填写TestRail的登录密码"/>#}
{#                                </div>#}
{#                            </div>#}
                            <div class="form-group modal-footer">
                                <div class="col-lg-9 col-lg-offset-3">
                                    <!--===footer button ===-->
                                    <div class="ak-footer-btn text-left">
                                        <input class="ak-zdl-createbtn" type="submit" value="提交">
                                        <input class="ak-zdl-createbtn cancel" type="reset" value="重置">
                                    </div>
                                    <!--===End footer button ===-->
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- Edit Product and User -->
        <div class="modal fade ak-min-fullwidth-modal ak-znews-addsort-modal" id="ProductAndUserModal" tabindex="-1"
             role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header clearfix">
                        <button type="button" class="close close-back" data-dismiss="modal"><span
                                class="sr-only">Close</span></button>
                        <h4 class="modal-title text-center">产品授权</h4>
                    </div>
                    <div class="modal-body col01 ac-amargin-tb20">
                        <form id="product_user" method="post" action="/product/user/" class="form-horizontal">
                            <div class="form-group">
                                <label class="col-lg-3 control-label">产品</label>
                                <div class="col-lg-5">
                                    <select class='ac-aselect' name="product" id="selectproductid">
                                        <option>选择产品</option>
                                        {% for i in productlist %}
                                            <option value="{{ i.pk }}"
                                                    {% if request.GET.product  == i.pk %}selected{% endif %}>{{ i.name }}</option>
                                        {% endfor %}

                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-3 control-label">用户</label>
                                <div class="col-lg-5" id="connecteduser" style="padding: 8px 5px">
                                    <option>选择用户</option>
                                    {% for user in alluser %}
                                        <label style="padding: 2px 2px">
                                            <input name="realname" type="checkbox" value="{{ user.pk }}"
                                                   {% if request.GET.realname  == user.pk %}checked{% endif %}>{{ user.realname }}
                                        </label>
                                    {% endfor %}
                                </div>
                            </div>


                            <div class="form-group modal-footer">
                                <div class="col-lg-9 col-lg-offset-3">
                                    <!--===footer button ===-->
                                    <div class="ak-footer-btn text-left">
                                        <input class="ak-zdl-createbtn" type="submit" value="提交">
                                        <input class="ak-zdl-createbtn cancel" type="reset" value="重置">
                                    </div>
                                    <!--===End footer button ===-->
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    {% else %}
       <div class="ak-zper-midbox ak-jsch-mid">
            <div class="ak-zper-inbox-title ak-jsch-title clearfix">
                <div class="ak-left ak-jsch-row3 ak-zper-fix-btnbox">
                    <span class="ak-zper-remindback"></span>
                    <span class="inbox-text">用户管理</span>
                </div>
                <div id="log_info" class="ac-addtips"></div>
            </div>
            <div class="col-md-12">
                <div style="text-align: center">
                    <p>形成天才的决定因素应该是勤奋。</p>
                    <p>……有几分勤学苦练是成正比例的。</p>
                    <p>加油吧！少年！！！</p>
                    <p>你没权限访问，可以找找管理员。</p>
                </div>
            </div>
        </div>
    {% endif %}
{% endblock %}
{% block script %}
    <script>
        function btn_skip_click() {
            var currpage = $('#curpage').val() === '' ? 1 : parseInt($('#curpage').val());
            // console.log(currpage);
            if (currpage > {{ page_obj.paginator.num_pages }}) {
                currpage = {{ page_obj.paginator.num_pages }};
            }
            if (currpage < 1) {
                currpage = 1;
            }
            var url = window.location.search.match(/page=(\d+|\s*)/) === null ? window.location.origin + (window.location.pathname + '?page=' + currpage + (window.location.search ? window.location.search.replace('?', '&') : '')) : window.location.search.replace(/page=(\d+|\s*)/, 'page=' + currpage);
            self.location = url;

            return false;
        }

        $('#curpage').keypress(function (event) {
            console.log(event.which);
            if (event.which == 13) {
                btn_skip_click()
            }
            event.stopPropagation();
        });

        /*     添加用户     */
        $(function () {
            $('#user_add')
                    .bootstrapValidator({
//        live: 'disabled',
                        message: 'This value is not valid',
                        feedbackIcons: {
                            valid: 'icon icon-ok',
                            invalid: 'icon icon-remove',
                            validating: 'icon icon-refresh'
                        },
                        fields: {
                            username: {
                                message: '无效的用户名',
                                validators: {
                                    notEmpty: {
                                        message: '登录用户名不能为空'
                                    },
                                    stringLength: {
                                        min: 4,
                                        max: 30,
                                        message: '用户名的长度为4-30字符'
                                    },
                                    regexp: {
                                        regexp: /^[a-zA-Z0-9_\.\@]+$/,
                                        message: '用户名只能由字母、数字和下划线组成'
                                    },
                                    different: {
                                        field: 'password',
                                        message: '用户名和密码不能一样'
                                    }
                                }
                            },
                            email: {
                                validators: {
                                    emailAddress: {
                                        message: '无效的邮箱地址'
                                    },
                                    notEmpty: {
                                        message: '邮箱地址不能为空'
                                    }
                                }
                            },
                            password: {
                                validators: {
                                    notEmpty: {
                                        message: '登录密码不能为空'
                                    },
                                    different: {
                                        field: 'username',
                                        message: '密码不能和用户名一样'
                                    }
                                }
                            },
                            confirmPassword: {
                                validators: {
                                    notEmpty: {
                                        message: '确认密码不能为空'
                                    },
                                    identical: {
                                        field: 'password',
                                        message: '密码和确认密码输入不一致'
                                    }
                                }
                            }
                        }
                    })

                    .on('success.form.bv', function (e) {

                        e.preventDefault();

                        var $form = $(e.target);

                        var bv = $form.data('bootstrapValidator');

                        $.post($form.attr('action'), $form.serialize(), function (result) {
                            $('#addUserModal').hide()
                            $('#log_info').addClass('bg-primary');
                            $('#log_info').css('display', 'block');
                            $('#log_info').html(result);
                            setTimeout("location.reload()", 1500);
                        })
                    });

        });

        /*     编辑用户     */
        $(function () {
            $('#user_edit')
                    .bootstrapValidator({
//        live: 'disabled',
                        message: 'This value is not valid',
                        feedbackIcons: {
                            valid: 'icon icon-ok',
                            invalid: 'icon icon-remove',
                            validating: 'icon icon-refresh'
                        },
                        fields: {
                            email: {
                                validators: {
                                    emailAddress: {
                                        message: '无效的邮箱地址'
                                    },
                                    notEmpty: {
                                        message: '邮箱地址不能为空'
                                    }
                                }
                            },
                            password: {
                                validators: {
                                    identical: {
                                        field: 'confirmPassword',
                                        message: '密码和确认密码输入不一致'
                                    }
                                }
                            },
                            confirmPassword: {
                                validators: {
                                    identical: {
                                        field: 'password',
                                        message: '密码和确认密码输入不一致'
                                    }
                                }
                            }
                        }
                    })
                    //         .bootstrapValidator({
                    // //        live: 'disabled',
                    //         message: 'This value is not valid',
                    //         feedbackIcons: {
                    //             valid: 'icon icon-ok',
                    //             invalid: 'icon icon-remove',
                    //             validating: 'icon icon-refresh'
                    //         },
                    //         fields: {
                    //             email: {
                    //                 validators: {
                    //                     emailAddress: {
                    //                         message: '无效的邮箱地址'
                    //                     },
                    //                     notEmpty: {
                    //                         message: '邮箱地址不能为空'
                    //                     }
                    //                 }
                    //             },
                    //             password: {
                    //                 validators: {
                    //                     different: {
                    //                         field: 'username',
                    //                         message: '密码不能和用户名一样'
                    //                     }
                    //                 }
                    //             },
                    //             confirmPassword: {
                    //                 validators: {
                    //                     identical: {
                    //                         field: 'password',
                    //                         message: '密码和确认密码输入不一致'
                    //                     }
                    //                 }
                    //             },
                    //         }
                    //     })

                    .on('success.form.bv', function (e) {

                        e.preventDefault();

                        var $form = $(e.target);

                        var bv = $form.data('bootstrapValidator');

                        $.post($form.attr('action'), $form.serialize(), function (result) {
                            $('#addEditModal').hide();
                            $('#log_info').addClass('bg-primary');
                            $('#log_info').css('display', 'block');
                            $('#log_info').html(result);
                            setTimeout("location.reload()", 1500);
                        })
                    });

        });

        /*用户管理页面-选择产品-关联用户*/
        $(document).ready(function () {
            $("#selectproductid").bind("change", function () {
                var s1SelectedVal = $('#selectproductid').val();
                if (s1SelectedVal != "") {
                    $.ajax({
                        type: "GET",
                        data: {'productid': s1SelectedVal},
                        url: "/setting/get/connecteduser/", //后台处理函数的url 这里用的是static url 需要与urls.py中的name一致
                        cache: false,
                        dataType: 'json',

                        success: function (result, TextStatus) {
                            $('input:checkbox').attr("checked", false);
                            if (result.length > 0) {
                                var allCheckbox = $('#connecteduser').find($("input"))
                                for (i = 0; i < result.length; i++) {
                                    for (j = 0; j < allCheckbox.length; j++) {
                                        {#                                              console.log($(allCheckbox[j]).parent())#}
                                        username_in_page = $(allCheckbox[j]).parent()[0].innerText
                                        {#                                              console.log(username_in_page)#}
                                        if (result[i].realname == $.trim(username_in_page)) {
                                            allCheckbox[j].checked = 'True'
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
            });

            /*     产品授权     */
            $('#product_user').submit(function () {
                $.ajax({
                    type: "POST",
                    data: $(this).serialize(),
                    url: "/setting/product/user/",
                    cache: false,
                    dataType: "html",
                    success: function (result, statues, xml) {
                        $('#ProductAndUserModal').hide()
                        $('#log_info').addClass('bg-primary');
                        $('#log_info').css('display', 'block');
                        $('#log_info').html(result);
                        setTimeout("location.reload()", 1200);
                    },
                    error: function () {
                        $('#log_info').addClass('bg-primary');
                        $('#log_info').css('display', 'block');
                        $('#log_info').html('授权失败');
                        alert('授权失败')
                    }
                });
                return false;
            });
        });
    </script>
{% endblock %}
